package com.casa.POI.dianping;

public class TimeUtils {
	
	private static long globalStartTime;
	
	public static String getTimeString(long timeInSec) {
		long hour = timeInSec / 3600;
		timeInSec = timeInSec - hour * 3600;
		long minute = timeInSec / 60;
		timeInSec  = timeInSec - minute * 60;
		long second = timeInSec;
		return String.format("%02d:%02d:%02d", hour, minute, second);
	}
	
	public static String getTimedText(String text) {
		String time = getTimeString(getGlobalElapsedTime());
		int length = time.length();
		String format = String.format("%%-%ds%%%ds", ConfigurationManager.getInstance().getConsoleCols() - length, length);
		return String.format(format, text, time);
	}
	
	public static long getElapsedTime(long startTime) {
		return System.currentTimeMillis() / 1000 - startTime;
	}
	
	public static long getGlobalStartTime() {
		return globalStartTime;
	}
	
	public static void resetGlobalStartTime() {
		globalStartTime = System.currentTimeMillis() / 1000;
	}
	
	public static long getGlobalElapsedTime() {
		return getElapsedTime(globalStartTime);
	}

	public static String getGlobalElapsedTimeString() {
		return getTimeString(getGlobalElapsedTime());
	}

}
